package com.xmb.wechat.delegate;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.xmb.wechat.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author lijiangop
 * @CreateTime 2019/8/15 09:51
 */
public class TabAdapter extends FragmentPagerAdapter {

    private List<BaseFragment> list_fragment = new ArrayList<>();//fragment列表
    private List<String>       list_Title    = new ArrayList<>();//tab名的列表

    public TabAdapter(FragmentManager fm, List<BaseFragment> list_fragment, List<String> list_Title) {
        super(fm);
        this.list_fragment.addAll(list_fragment);
        this.list_Title.addAll(list_Title);
    }

    @Override
    public Fragment getItem(int position) {
        Fragment fragment = list_fragment.get(position);
        return fragment;
    }

    @Override
    public int getCount() {
        return list_Title.size();
    }

    //此方法用来显示tab上的名字
    @Override
    public CharSequence getPageTitle(int position) {
        return list_Title.get(position % list_Title.size());
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        super.destroyItem(container, position, object);
    }
}
